package com.xdf.zipperdye.service;

import com.xdf.zipperdye.dao.business.MaterialMapper;
import com.xdf.zipperdye.model.BillCode;
import com.xdf.zipperdye.model.Material;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Service
public class MaterialServiceImpl implements MaterialService {
    @Autowired
    private MaterialMapper dao;
    @Autowired
    private BillCodeService billCodeService;

    @Override
    public int deleteByPrimaryKey(Integer iid) {
        return dao.deleteByPrimaryKey(iid);
    }

    @Transactional
    @Override
    public Material insert(Material record) {
        String billCode = billCodeService.getNewBillCode(record.getBill_type());
        record.setBill_code(billCode);
        int ret = dao.insert(record);
        return dao.selectByPrimaryKey(record.getIid());
    }

    @Transactional
    @Override
    public Material insertSelective(Material record) {
        String billCode = billCodeService.getNewBillCode(record.getBill_type());
        record.setBill_code(billCode);
        int ret = dao.insertSelective(record);
        return dao.selectByPrimaryKey(record.getIid());
    }

    @Override
    public Material selectByPrimaryKey(Integer iid) {
        return dao.selectByPrimaryKey(iid);
    }

    @Override
    public int updateByPrimaryKeySelective(Material record) {
        return dao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Material record) {
        return dao.updateByPrimaryKey(record);
    }

    @Override
    public List<Material> selectAll() {
        return dao.selectAll();
    }

}
